import { NAlert, type AlertProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
export type AlertFactoryConstructorType = {
    props?: AlertProps;
    attrs?: HTMLAttributes;
    defaultSlot?: BaseComponentType;
    headerSlot?: BaseComponentType;
    iconSlot?: BaseComponentType;
}
export class AlertFactory {
  private props: AlertProps = {};
  private attrs: HTMLAttributes = {};
  private defaultSlot: BaseComponentType = null;
  private headerSlot: BaseComponentType = null;
  private iconSlot: BaseComponentType = null;

  constructor(data?: AlertFactoryConstructorType) {
    if (data?.props) this.setProps(data.props);
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
    if (data?.headerSlot) this.setHeader(data.headerSlot);
    if (data?.iconSlot) this.setIcon(data.iconSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this;
  }
  setProps(props: AlertProps) {
    this.props = props;
    return this;
  }
  setDefault(component: BaseComponentType) {
    this.defaultSlot = component;
    return this;
  }
  setHeader(component: BaseComponentType) {
    this.headerSlot = component;
    return this;
  }
  setIcon(component: BaseComponentType) {
    this.iconSlot = component;
    return this;
  }

  create() {
    return (
      <NAlert {...this.props} {...this.attrs}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
          header:
            this.headerSlot != null ? () => getSlotsDom(this.headerSlot) : null,
          icon: this.iconSlot != null ? () => getSlotsDom(this.iconSlot) : null,
        }}
      </NAlert>
    );
  }
}
